package com.yfp.machine.api.factory;

import com.yfp.common.core.domain.R;
import com.yfp.machine.api.RemoteMachineService;
import com.yfp.machine.domain.MachineDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 
 * @version 1.0
 * @date 2024-07-13 14:25
 */
@Component
public class RemoteMachineFallbackFactory implements FallbackFactory<RemoteMachineService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteMachineFallbackFactory.class);

    @Override
    public RemoteMachineService create(Throwable cause) {
        log.error("Machine服务调用失败:{}", cause.getMessage());
        return new RemoteMachineService() {
            @Override
            public R<MachineDto> selectOne(String id) {
                return R.fail("获取设备列表失败：" + cause.getMessage());
            }
        };
    }
}
